package com.yycwxt.modules.admin.buyprice;

import com.yycwxt.common.ReturnResult;
import com.yycwxt.domain.BuyPrice;
import com.yycwxt.domain.GoodsPack;
import com.yycwxt.modules.admin.goodspack.GoodsPackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
@Validated
@RequestMapping("/buyprice")
public class BuyPriceController {
    private BuyPriceService buyPriceService;
    @Autowired
    public BuyPriceController ( BuyPriceService buyPriceService) {
        this.buyPriceService = buyPriceService;
    }
    @GetMapping()
    @ApiOperation("查询全部采购价格")
    public ReturnResult selectAll(){
        return ReturnResult.buildSuccessResult(buyPriceService.list());
    }
    @GetMapping("/{id}")
    @ApiOperation("按ID查找采购价格")
    public ReturnResult getById(@PathVariable Integer id){
        return ReturnResult.buildSuccessResult(buyPriceService.getById(id));
    }
    @PostMapping()
    @ApiOperation("新增采购价格")
    public ReturnResult addBuyPrice(@ApiParam(name = "buyprice对象",required = true,type = "buyprice")@RequestBody@Validated BuyPrice buyPrice){
        return  ReturnResult.buildSuccessResult(buyPriceService.save(buyPrice));
    }
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除buyprice")
    public ReturnResult deleteBuyPrice(@ApiParam(name = "id",required = true,type = "int")@PathVariable Integer id){
        return ReturnResult.buildSuccessResult(buyPriceService.removeById(id));
    }
    @PutMapping()
    @ApiOperation("根据id修改BuyPrice")
    public ReturnResult updateBuyPrice(@Validated @ApiParam(name = "buyprice对象",required = true,type = "buyprice")@RequestBody BuyPrice buyPrice){
        return  ReturnResult.buildSuccessResult(buyPriceService.updateById(buyPrice));
    }
}
